<template>
  <basic :field="field">
    <template slot="fieldProps">
      <FormItem label="是否支持多选">
        <i-switch v-model="fieldProps.multiple" @on-change="handleChange"/>
      </FormItem>
    </template>
  </basic>
</template>

<script>
import basic from './basic.vue';

export default {
  name: 'fieldSelect',
  components: {
    basic
  },
  props: {
    field: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      fieldProps: {
        multiple: false
      }
    };
  },
  methods: {
    handleChange() {
      this.$parent.$parent.$emit('on-change-field', {
        props: { multiple: this.fieldProps.multiple ? 1 : 0 }
      });
    },
    init() {
      this.fieldProps.multiple = this.field.props.multiple == 1;
    }
  },

  created() {
    this.init();
  },
  watch: {
    field: {
      handler() {
        this.init();
      },
      deep: true
    }
  }
};
</script>
